pub mod message;

use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};

/// # Websocket接收
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct SatoriClientWs<D> {
    pub method: String,
    pub data: D,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct SatoriList<D> {
    pub data: Vec<D>,
    pub next: String,
}

impl<D> SatoriList<D> {
    pub fn new(data: Vec<D>, next: &str) -> Self {
        Self {
            data,
            next: next.to_string(),
        }
    }
}

pub fn json_to_self<D: DeserializeOwned>(text: &str) -> serde_json::Result<SatoriClientWs<D>> {
    serde_json::from_str::<SatoriClientWs<D>>(&text)
}